package com.neborosoft.lib.strings;

import com.neborosoft.lib.utilities.Utilities;

/**
 * Project: FlyingDog
 * User: stikhonenko
 * Date: 2/13/13
 * Time: 4:23 PM
 */
public class Strings {
    public static final String setCharAt(String string, int index, char ch){
        char[] array = string.toCharArray();
        array[index] = ch;
        return array.toString();
    }

    public static String join(Object[] array, String separator){
        StringBuilder stringBuilder = new StringBuilder();
        for(int i = 0; i < array.length; i++){
            stringBuilder.append(array[i]);
            if(i != array.length - 1){
                stringBuilder.append(separator);
            }
        }

        return stringBuilder.toString();
    }

    public static String join(String separator, Object... array){
        return join(array, separator);
    }

    public static String join(Object separator, Object... array){
        return join(separator.toString(), array);
    }

    public static String joinObjectFields(Object object, String separator){
        return join(Utilities.objectToPropertiesArray(object), separator);
    }
}
